1
|
|
|
/** |
2
|
|
|
* Asynchronously save all settings in the current settings page to the database. |
3
|
|
|
* Shows an error notification if errors occur. Shows a success notification |
4
|
|
|
* otherwise. |
5
|
|
|
* |
6
|
|
|
* @param {Function} done |
7
|
|
|
*/ |
8
|
|
|
Amarkal.settings.save = function( done ) |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
Amarkal.settings._postData('save',function(res){ |
|
|
|
|
11
|
|
|
|
12
|
|
|
$('#amarkal-settings-form').amarkalUIForm('setData', res.values, res.errors); |
13
|
|
|
Amarkal.settings._clearNotices(); |
|
|
|
|
14
|
|
|
|
15
|
|
|
if(!$.isEmptyObject(res.errors)) { |
16
|
|
|
for(var name in res.errors) { |
|
|
|
|
17
|
|
|
var $comp = $('[amarkal-component-name="'+name+'"]'), |
18
|
|
|
props = $comp.amarkalUIComponent('getProps'); |
19
|
|
|
|
20
|
|
|
$comp.amarkalUIComponent('makeInvalid'); |
21
|
|
|
$comp.parent() |
22
|
|
|
.children('.amarkal-settings-error') |
23
|
|
|
.addClass('amarkal-visible') |
24
|
|
|
.html(res.errors[name]); |
25
|
|
|
|
26
|
|
|
Amarkal.settings.notifier.error('Some errors have occured, see below for more information.'); |
27
|
|
|
Amarkal.settings.sections.flag('error', props.section); |
28
|
|
|
Amarkal.settings.fields.flag('error', props.name); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
} |
32
|
|
|
else { |
33
|
|
|
Amarkal.settings.notifier.success('Settings saved', 3000); |
34
|
|
|
} |
35
|
|
|
done(); |
36
|
|
|
}); |
37
|
|
|
}; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Asynchronously reset all settings in the current settings page to their |
41
|
|
|
* default values and erase all data from the database. Shows a success |
42
|
|
|
* notification upon completion. |
43
|
|
|
* |
44
|
|
|
* @param {Function} done |
45
|
|
|
*/ |
46
|
|
|
Amarkal.settings.resetAll = function( done ) |
47
|
|
|
{ |
48
|
|
|
Amarkal.settings._postData('reset_all',function(res){ |
|
|
|
|
49
|
|
|
|
50
|
|
|
$('#amarkal-settings-form').amarkalUIForm('setData', res.values, res.errors); |
51
|
|
|
Amarkal.settings._clearNotices(); |
|
|
|
|
52
|
|
|
Amarkal.settings.notifier.success('Default settings applied', 3000); |
53
|
|
|
|
54
|
|
|
done(); |
55
|
|
|
}); |
56
|
|
|
}; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Asynchronously reset all settings in the current settings section to their |
60
|
|
|
* default values and erase all section data from the database. Shows a success |
61
|
|
|
* notification upon completion. |
62
|
|
|
* |
63
|
|
|
* @param {Function} done |
64
|
|
|
*/ |
65
|
|
|
Amarkal.settings.resetSection = function( done ) |
66
|
|
|
{ |
67
|
|
|
Amarkal.settings._postData('reset_section',function(res){ |
|
|
|
|
68
|
|
|
|
69
|
|
|
$('#amarkal-settings-form').amarkalUIForm('setData', res.values, res.errors); |
70
|
|
|
Amarkal.settings._clearNotices(); |
|
|
|
|
71
|
|
|
Amarkal.settings.notifier.success('Default settings applied for the section <strong>'+Amarkal.settings.sections.getTitle(Amarkal.settings.sections.activeSection)+'</strong>', 3000); |
72
|
|
|
|
73
|
|
|
done(); |
74
|
|
|
}); |
75
|
|
|
}; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Reset all components and clear errors |
79
|
|
|
*/ |
80
|
|
|
Amarkal.settings._clearNotices = function() |
81
|
|
|
{ |
82
|
|
|
// Reset all components |
83
|
|
|
$('.amarkal-ui-component').amarkalUIComponent('reset'); |
84
|
|
|
$('.amarkal-settings-error').removeClass('amarkal-visible').html(''); |
85
|
|
|
Amarkal.settings.sections.unflagAll(); |
|
|
|
|
86
|
|
|
Amarkal.settings.fields.unflagAll(); |
87
|
|
|
}; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Send serialized form data to be processed in the backend by the function given |
91
|
|
|
* in the 'action' variable. |
92
|
|
|
* |
93
|
|
|
* @param {string} action |
94
|
|
|
* @param {Function} done |
95
|
|
|
*/ |
96
|
|
|
Amarkal.settings._postData = function( action, done ) |
97
|
|
|
{ |
98
|
|
|
var data = $('#amarkal-settings-form').amarkalUIForm('getData'); |
99
|
|
|
$('#amarkal-settings-form').find('input[name^="_amarkal"]').each(function(){ |
100
|
|
|
data[$(this).attr('name')] = $(this).val(); |
101
|
|
|
}); |
102
|
|
|
|
103
|
|
|
// Set the active section (if applicable) |
104
|
|
|
data._amarkal_settings_section = Amarkal.settings.sections.activeSection; |
|
|
|
|
105
|
|
|
|
106
|
|
|
$.post(ajaxurl, { |
|
|
|
|
107
|
|
|
action: 'amarkal_settings_'+action, |
108
|
|
|
data: data |
109
|
|
|
}, done); |
110
|
|
|
}; |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.